﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ElectronicsMarket.Service.IService;
using ElectronicsMarket.Service.Models;

namespace ElectronicsMarket.Service.ServiceImpl
{
    public class OrderDetailsImpl:IOrderDetailsServices
    {
        private ElectronicsMarketDBClassesDataContext eMEntity;
        public OrderDetailsImpl()
        {
            eMEntity = new ElectronicsMarketDBClassesDataContext();
        }

        public List<ORDERS_DETAIL> getOrderDetailByID(int id)
        {
            List<ORDERS_DETAIL> lstorderdetail = eMEntity.ORDERS_DETAILs.Where(o => o.ORDERS_ID == id).ToList();
            return lstorderdetail;
        }

        public bool addNewOrderDetail(long orderId, long productId, int amount, decimal price)
        {
            try
            {
                ORDERS_DETAIL orderDetail = new ORDERS_DETAIL();
                orderDetail.ORDERS_ID = orderId;
                orderDetail.PRODUCT_ID = productId;
                orderDetail.AMOUNT = amount;
                orderDetail.PRICE = price;
                eMEntity.ORDERS_DETAILs.InsertOnSubmit(orderDetail);
                eMEntity.SubmitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }
        
    }
}